package edu.pku.sei.modeler.uml.commands.compositestructure;

import org.eclipse.draw2d.geometry.Rectangle;

import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.StructuredClasses.StructuredClass;
import edu.pku.sei.modeler.uml.commands.NestedElementCreateCommand;

public class NestedStructuredClassCreateCommand extends
		NestedElementCreateCommand {

	private StructuredClass fatherModel;
	private StructuredClass childModel;
	public NestedStructuredClassCreateCommand(MetaNode node,
			MetaNode fatherNode, Rectangle constraint) {
		super(node, fatherNode, constraint);
	}
	@Override
	public boolean canExecute() {
		if (fatherNode.getModelElement() instanceof StructuredClass
				&& node.getModelElement() instanceof StructuredClass) 
			return super.canExecute();
		else return false;
	}
	
	@Override
	protected void updateModelElement() {
		this.fatherModel = (StructuredClass) fatherNode.getModelElement();
		this.childModel = (StructuredClass) node.getModelElement();
		
		fatherModel.getMember().add(childModel);
	}
	
	@Override
	protected void undoModelElement() {
		this.fatherModel.getMember().remove(childModel);
	}
}
